<#import "/spring.ftl" as spring />
<div class="content">
	<div class="tab_bar">
		<ul>
			<li class="tab_index" onclick="setTabContent(this);">添加栏目</li>
		</ul>
		<button class="btn_tabbar" onclick="submit(this);" return="channel/list.do">保 存</button>
	</div>


	<form id="myForm" action="channel/update.do" method="post" class="form-horizontal" onsubmit="return false;">



 	<div class="tab_content">
		<div class="tab_item tab_show">

			<div class="control-group">
				<label class="control-label">所属栏目：</label>
				<div class="controls">
					<select class="select_for_add"  name="pid">
						<option value="0"> -------- 顶级栏目 -------- </option>
						<#include "/common/channelSelect.html" />
						<@channelTree id = 0 node = -1/>
					</select>
					<div class="help-block">

					</div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">栏目名称：</label>
				<div class="controls">
					<input class="input_for_add" id="name" name="name" type="text" />
					<div class="help-block"></div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">语言引用：</label>
				<div class="controls">
					<input class="input_for_add" name="langkey" type="text" />
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">重定向地址：</label>
				<div class="controls">
					<input class="input_for_add" id="redirect" name="redirect" type="text" />
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目关键字：</label>
				<div class="controls">
					<input class="input_for_add" name="keywords" type="text" />
					<div class="help-block"></div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">栏目描述：</label>
				<div class="controls">
					<textarea class="textarea_for_add" name="description"></textarea>
					<div class="help-block"></div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">栏目图标：</label>
				<div class="controls">
					<input id="channelIcon" class="input_for_add" name="icon" type="text" />

					<button onclick="uploadImage()">上传图片</button>
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目模板：</label>
				<div class="controls">
					<select id="template" name="template">
						<#list templateList as tpl>
							<option value="${tpl}">${tpl}</option>
						</#list>
					</select>
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目地址：</label>
				<div class="controls">
					<input class="input_for_add" name="url" type="text" value="defalut"/>
					<div class="help-block">地址不能重复哦</div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目属性：</label>
				<div class="controls">
				 	<div>
						<select class="select_for_add" style="width: 60px;" name="hide">
							<option value="1">显示</option>
							<option value="0">隐藏</option>
						</select>
						&nbsp; &nbsp;
						排序：<input class="input_for_add" name="sort" style="width:50px;" value="0" type="text" />
						&nbsp; &nbsp;
						条数：<input class="input_for_add" name="rows" style="width:50px;" value="10" type="text" />

					</div>
				</div>
			</div>

			<div class="control-group">
				<script type="text/plain" id="mushroomeditor" name="content"  style="height:350px;"></script>
			</div>


		</div>
	</div>
	</form>
</div>
<script type="text/javascript">

//	$("#template").val("");

    //初始化UE编辑器
    $(function(){
        $("input[name='type']").click(function(){
            editor.execCommand( 'source');
            if($(this).val() == 1){
                editor.setDisabled();
            }else{
                editor.setEnabled();
            }
            editor.setContent('');
        });



        if(window.editor != null){
            window.editor.destroy();
        }

        //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        window.editor = UE.getEditor('mushroomeditor');

        window.editor.ready(function(){
            $("#title").focus();

            var status = editor.queryCommandState( 'source' );
            if(status != 1){

            }


        });

    });

    function submit(obj){
        window.editor.sync();//手动提交需要手动同步编辑器数据

        submitActionForm(obj);

    }

    var _editor = UE.getEditor('upload_ue');
    _editor.ready(function () {
        console.log("ueditor success!")
        //设置编辑器不可用
        _editor.setDisabled();
        //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
        _editor.hide();
        //侦听图片上传
        _editor.addListener('beforeInsertImage', function (t, arg) {
            console.log(arg);
        })
        //侦听文件上传
        _editor.addListener('afterUpfile', function (t, arg) {
            console.log(arg);
            $("#channelIcon").attr("value", arg[0].src);
        })
    });

    function uploadImage(){
        var myImage = _editor.getDialog("insertimage");
        myImage.open();
    }
</script>